/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipti.br.tag.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import org.ipti.br.tag.util.EncryptionUtil;

/**
 *
 * @author root
 */
@Entity
public class AdditionalInfo extends AbstractEntity{
    
    @Column(nullable=false, length=80)
    private String value;
    
    @ManyToOne
    @JoinColumn(nullable=false)
    private Person person;
    
    @ManyToOne
    @JoinColumn(nullable=false)
    private AdditionalInfoType additionalInfoType;

    public AdditionalInfo() {
    }
    
    @Override
    public void generateHash(){
        if(getId() == null){
            String additionalInfoHashString = "" + this.getValue()
                    + ((this.getPerson() != null) ? this.getPerson().getId() : null)
                    + ((this.getAdditionalInfoType() != null) ? this.getAdditionalInfoType().getId() : null);
            this.setId(Long.valueOf(EncryptionUtil.encrypt(additionalInfoHashString).hashCode()));
        }
    }

    public AdditionalInfo(String value, Person person, AdditionalInfoType additionalInfoType) {
        this.value = value;
        this.person = person;
        this.additionalInfoType = additionalInfoType;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public Person getPerson() {
        return person;
    }

    public void setPerson(Person person) {
        this.person = person;
    }

    public AdditionalInfoType getAdditionalInfoType() {
        return additionalInfoType;
    }

    public void setAdditionalInfoType(AdditionalInfoType additionalInfoType) {
        this.additionalInfoType = additionalInfoType;
    }
}
